﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ERPStore.NewsLetters.Services
{
	public static class ModelsExtensions
	{
		public static IList<T> GetPaged<T>(this IQueryable<T> list, int index, int pageSize, out int count)
		{
			count = 0;
			if (list == null)
			{
				return new List<T>();
			}
			count = list.Count();
			var result = list.Skip(index * pageSize).Take(pageSize);

			return result.ToList();
		}

		public static Models.NewsLetter GetById(this IQueryable<Models.NewsLetter> list, int id)
		{
			return list.Where(i => i.Id == id).SingleOrDefault();
		}

		//public static Models.NewsLetter GetByLandingLink(this IQueryable<Models.NewsLetter> list, string landingLink)
		//{
		//    return list.Where(i => i.LandingLink.Equals(landingLink, StringComparison.InvariantCultureIgnoreCase)).SingleOrDefault();
		//}

		public static Models.Campaign GetCampaignById(this IQueryable<Models.Campaign> list, int id)
		{
			return list.Where(i => i.Id == id).SingleOrDefault();
		}

	}
}
